﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DBUtility;
using TierService;//Please add references
namespace TierApplication
{

    public partial class T_OrderInvoice
    {
        public DataSet GetSaleInvoiceList(string strWhere)
        {
            SqlParameter[] parameters = { new SqlParameter("@ac_where ", SqlDbType.VarChar, 500) };
            parameters[0].Value = strWhere;
            DataSet ds = DBUtility.DbHelperSQL.RunProcedure("dbo.GetSaleInvoiceList", parameters, "Num");
            return ds;
        }


        public DataSet GetSaleInvoiceInfoByInvoiceID(string sInvoiceID)
        {
            StringBuilder strSql = new StringBuilder();
            return GetSaleInvoiceList(" and a.InvoiceID='" + sInvoiceID + "'");

        }

        public DataSet GetSaleInvoiceInfoByOrderID(string sOrderID)
        {
            StringBuilder strSql = new StringBuilder();
            return GetSaleInvoiceList(" and b.OrderID='" + sOrderID + "'");
        }

        public DataSet GetSaleInvoiceingList(string strWhere)
        {
            SqlParameter[] parameters = { new SqlParameter("@ac_where ", SqlDbType.VarChar, 500) };
            parameters[0].Value = strWhere;
            DataSet ds = DBUtility.DbHelperSQL.RunProcedure("dbo.GetSaleInvoiceingList", parameters, "Num");
            return ds;
        }

        public DataSet GetBuyInvoiceInfoByOrderID(string sOrderID)
        {
            return GetBuyInvoiceList(" and b.OrderID='" + sOrderID + "'");
        }

        public DataSet GetBuyInvoiceList(string strWhere)
        {
            SqlParameter[] parameters = { new SqlParameter("@ac_where ", SqlDbType.VarChar, 500) };
            parameters[0].Value = strWhere;
            DataSet ds = DBUtility.DbHelperSQL.RunProcedure("dbo.GetBuyInvoiceList", parameters, "Num");
            return ds;
        }

        public DataSet GetBuyInvoiceingList(string strWhere, string sType)
        {
            SqlParameter[] parameters = { 
                                              new SqlParameter("@ac_where ", SqlDbType.VarChar, 500),
                                        new SqlParameter("@ac_type ", SqlDbType.VarChar, 1)};
            parameters[0].Value = strWhere;
            parameters[1].Value = sType;
            DataSet ds = DBUtility.DbHelperSQL.RunProcedure("dbo.GetBuyInvoiceingList", parameters, "Num");
            return ds;
        }

        public DataSet GetSaleInvoicedList(string strWhere)
        {
            SqlParameter[] parameters = { new SqlParameter("@ac_where ", SqlDbType.VarChar, 500) };
            parameters[0].Value = strWhere;
            DataSet ds = DBUtility.DbHelperSQL.RunProcedure("dbo.GetSaleInvoicedList", parameters, "Num");
            return ds;
        }

        public void SubmitAudit(string sInvoiceID)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_OrderInvoice ");
            strSql.Append("Set OrderStatus='1'");
            strSql.Append(" where InvoiceID='" + sInvoiceID + "' ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }


        public void AuditInvoiceApp(string sInvoiceID, string sUserID, string sInvoiceAuditRemark)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_OrderInvoice ");
            strSql.Append("Set OrderStatus='2',InvoiceAuditUserID='" + sUserID + "',InvoiceAuditDate=getdate(),InvoiceAuditRemark='" + sInvoiceAuditRemark + "'");
            strSql.Append(" where InvoiceID='" + sInvoiceID + "' ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        public void DeAuditInvoiceApp(string sInvoiceID, string sUserID, string sAuditRemark)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update T_OrderInvoice ");
            strSql.Append("Set OrderStatus='0',InvoiceAuditRemark='" + sAuditRemark + "'");
            strSql.Append(" where InvoiceID='" + sInvoiceID + "' ");
            DbHelperSQL.ExecuteSql(strSql.ToString());
        }

        public DataSet GetRptSaleInvoiceReturnFeeList(string strWhere, string sPayStatus)
        {
            SqlParameter[] parameters = { 
                                     new SqlParameter("@ac_where ", SqlDbType.VarChar, 500),
                                     new SqlParameter("@ac_PayStatus ", SqlDbType.VarChar, 1)};
            parameters[0].Value = strWhere;
            parameters[1].Value = sPayStatus;
            DataSet ds = DBUtility.DbHelperSQL.RunProcedure("dbo.GetRptSaleInvoiceReturnFeeList", parameters, "Num");
            return ds;
        }
    }
}

